package com.studerb.tests.service;

import javax.swing.JOptionPane;
import org.junit.Test;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import org.springframework.util.StopWatch;

import com.studerb.model.Server;
import com.studerb.service.*;
import com.studerb.service.interfaces.INewsGroupService;

public final class TestGroupService extends AbstractDependencyInjectionSpringContextTests{

	private INewsGroupService groupService;
	private ServerService serverService;
		
	@Override
	protected String[] getConfigLocations() {
		return new String[] { "applicationContext.xml" };
	}

	public void setGroupService(INewsGroupService groupService) {
		this.groupService = groupService;
	}

	public void setServerService(ServerService serverService){
		this.serverService = serverService;
	}
	
	@Test
	public void testUpdateGroups() {
		StopWatch timer = new StopWatch();
		JOptionPane.showMessageDialog(null, "Make sure the network is ON");
		try {
			timer.start();
			serverService.deleteAllServers();
			Server server = new Server("news.giganews.com", new Integer(119), new Integer(9),"gn115371", "n!iC3n", true, true);
	    	serverService.addServer(server);
	    	assertNotNull(server.getId());
	    	groupService.updateNewsGroups();
			assertTrue(groupService.getNewsGroups().size() > 0);
			serverService.deleteServer(server);
		} catch (Exception e) {
			e.printStackTrace();
			fail("Should not have caught exception: " + e.getMessage());
		}
		timer.stop();
		logger.info(timer.prettyPrint());
	}
	
	//List<NewsGroup> getNewsGroups() throws ServiceException;
/*	@Test
	public void testGetNewsGroups() {
		fail("not implemented");
	}
	
	//void downloadAllHeaders() throws ServiceException;
	@Test 
	public void testDownloadAllHeaders(){
		fail("Not implemented");
	}
	
	//void downloadHeaders(int first, int last) throws ServiceException;
	@Test
	public void testDownloadHeaders(int first, int last) {
		fail("Not implemented");
	}
	
	//void downloadNewHeaders() throws ServiceException;
	@Test
	public void testDownloadNewHeaders(){
		fail("Not implemented");
	}
	
	//void setSubscribed(NewsGroup newsGroup, boolean isSubscribed) throws ServiceException;
	@Test
	public void testSetSubscribed(NewsGroup newsGroup, boolean isSubscribed){
		fail("Not implemented");	
	}
	*/
}
